package com.maduar.mybatis.demo.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.maduar.mybatis.demo.entity.UserEntity;
import com.maduar.mybatis.demo.vo.RoleCountVo;
import com.maduar.mybatis.demo.vo.UserPageRes;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Description:
 *
 * @author maduar maduar@163.com
 * @date 2021-04-10 18:15
 */
@Repository
public interface UserMapper extends BaseMapper<UserEntity> {
    // ${ew.customSqlSegment} 分页条件

    @Select("SELECT email FROM user ")
    List<String> getEmail();

    @Select(" SELECT A.count, A.ro_id as roleId, B.role_name AS roleName  " +
            " FROM (  " +
            "  SELECT count(ro_id) AS count, ro_id  " +
            "  FROM `user`  " +
            "  GROUP BY ro_id  " +
            "  ORDER BY count  " +
            " ) AS A  " +
            "INNER JOIN `role` AS B ON A.ro_id = B.ro_id ")
    List<RoleCountVo> countRole();

    IPage<UserPageRes> pageSelect(IPage<UserPageRes> page,
                                  @Param(Constants.WRAPPER) Wrapper<UserPageRes> q);

    List<UserEntity> getAll();
}
